
package com.mengmeizi.util;



import com.mengmeizi.R;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

public class CustomDialog extends Dialog {
    private View view;

    private Button leftButton, rightButton;

    private TextView titleTextView, contentTextView;

    private LinearLayout titleLayout, leftLayout, rightLayout, buttonLayout;

    private CheckBox checkBox;

    public CustomDialog(Context context) {
        this(context, R.style.customDialogStyle);
    }

    public CustomDialog(Context context, int theme) {
        super(context, theme);
        view = LayoutInflater.from(context).inflate(R.layout.custom_dialog, null);
        leftButton = (Button) view.findViewById(R.id.leftButton);
        rightButton = (Button) view.findViewById(R.id.rightButton);
        contentTextView = (TextView) view.findViewById(R.id.content);
        buttonLayout = (LinearLayout) view.findViewById(R.id.buttonLayout);
        titleTextView = (TextView) view.findViewById(R.id.title);
        titleLayout = (LinearLayout) view.findViewById(R.id.titleLayout);
        leftLayout = (LinearLayout) view.findViewById(R.id.leftLayout);
        rightLayout = (LinearLayout) view.findViewById(R.id.rightLayout);
        checkBox = (CheckBox) view.findViewById(R.id.ckbCheckBox);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(view);
    }

    public void setLeftButtonOnClick(android.view.View.OnClickListener onClickListener) {
        leftButton.setOnClickListener(onClickListener);
    }

    public void setRightButtonOnClick(android.view.View.OnClickListener onClickListener) {
        rightButton.setOnClickListener(onClickListener);
    }

    public void setTitle(String title) {
        titleTextView.setText(title);
    }

    public void setContent(String content) {
        contentTextView.setText(content);
    }

    public void setLeftButtonText(String text) {
        leftButton.setText(text);
    }

    public Button leftButton() {
        return leftButton;
    }

    public Button rightButton() {
        return rightButton;
    }

    public void setRightButtonText(String text) {
        rightButton.setText(text);
    }

    public void setCheckBox$CheckedChangeListener(CompoundButton.OnCheckedChangeListener listener) {
        checkBox.setOnCheckedChangeListener(listener);
    }

    public CheckBox getCheckBox() {
        return checkBox;
    }

    public void hideLeftButton() {
        buttonLayout.removeView(leftLayout);
    }

    public void hideRightButton() {
        buttonLayout.removeView(rightLayout);
    }

    public void hideButton() {
        buttonLayout.setVisibility(View.GONE);
    }

    public void hideTitle() {
        titleTextView.setVisibility(View.GONE);
        LayoutParams layoutParams = (LayoutParams) titleLayout.getLayoutParams();
        layoutParams.height = 2;
        titleLayout.setLayoutParams(layoutParams);
    }

    public void hideCheckBox() {
        checkBox.setVisibility(View.GONE);
    }

}
